home *** CD-ROM | disk | FTP | other *** search
/ Kompuutteri Kaikille K-CD 2002 #8 / K-CD_2002-08.iso / WatzNew / data.cab / HTTP GET.pl < prev    next >
Text File  |  2000-07-02  |  2KB  |  58 lines

  1. #%DESCRIPTION%|=|Retrieves the specified document via HTTP and searches text with regular expression. Handles automatic browser redirection.
  2. #%URL%|?|http://www.yoursite.com/path/file.ext?params|Document URL (http:// only)
  3. #%AUTO_REDIRECT%|?|1|Handle auto-redirection? ('1' = yes, otherwise no)
  4. #%REG_EXP%|?|<TITLE>(.*?)</TITLE>|Regular Expression
  5. #%MAX_MATCHES%|?|1|How many matches to allow?
  6. #%MSG_TEMPLATE%|?|Title: $1|Message template for each match
  7. #%TITLE%|=|HTTP GET %URL%
  8. #%MESSAGE%|=|%1
  9.  
  10. # ------------------------------------------------------------------------------
  11. # General HTTP GET script by A.I.Studio / Igor Afanasyev
  12. # ------------------------------------------------------------------------------
  13.  
  14. require 'http.lib';
  15.  
  16. # ------------------------------------------------------------------------------
  17.  
  18. $Url = $ENV{'URL'};
  19. ($Url eq '') && &ERR('URL is not defined');
  20.  
  21. $RegExp = $ENV{'REG_EXP'};
  22. #($RegExp eq '') && &ERR('REG_EXP is not defined');
  23.  
  24. $Message = $ENV{'MSG_TEMPLATE'};
  25. ($Message eq '') && ($Message = '$1');
  26.  
  27. $AutoRedirect = ($ENV{'AUTO_REDIRECT'} eq '1');
  28.  
  29. $MaxMatches = $ENV{'MAX_MATCHES'};
  30. ($MaxMatches == 0) && ($MaxMatches = 1);
  31.  
  32. # ------------------------------------------------------------------------------
  33.  
  34. if ($AutoRedirect) {
  35.   ($_,$Url) = &HttpGetUrlAutoRedirect($Url, 1);
  36. } else {
  37.   &HttpGetUrl($Url, 1);
  38. }  
  39.  
  40. undef my $out;
  41. my $re = qr|$RegExp|si;
  42.  
  43. if ($RegExp ne '') {
  44.   while (($HttpBody =~ m|$re|g) && ($MaxMatches > 0)) {
  45.     my $e = '$out .= "'.$Message.'"';
  46.     eval($e);
  47.     $MaxMatches--;
  48.   }
  49.   $out = &ExpandUrls(&Squeeze($out),$Url);
  50. } else {
  51.   $out = 'REG_EXP is not defined';
  52. }
  53.  
  54. ($out eq '') && ($out = 'No pattern match found');
  55.  
  56. &MSG($out);
  57. &MSG($Url);
  58.